package br.com.murashige.swt.widget.fasttable;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;

public class FastTable extends Canvas {

	/**
	 * Constructs a new instance of this class given its parent and a style
	 * value describing its behavior and appearance.
	 * <p>
	 * 
	 * @param parent a composite control which will be the parent of the new
	 *        instance (cannot be null)
	 * @param style the style of control to construct
	 * @throws IllegalArgumentException <ul>
	 *         <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
	 *         </ul>
	 * @throws org.eclipse.swt.SWTException <ul>
	 *         <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread
	 *         that created the parent</li>
	 *         </ul>
	 */
	public FastTable(Composite parent, int style) {
		super(parent, checkStyle(style));
	}

	/**
	 * Filters out unnecessary styles, adds mandatory styles and generally
	 * manages the style to pass to the super class.
	 * 
	 * @param style user specified style.
	 * @return style to pass to the super class.
	 */
	private static int checkStyle(int style) {
		int mask = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL;
		int newStyle = style & mask;
		newStyle |= SWT.DOUBLE_BUFFERED;
		return newStyle;
	}

}
